#include <iostream>
#include <cstring>
char* removechars(char* str, char* remove){
    bool flags[128];
    for(int i=0;i<128;i++){
        flags[i]=false;
    }
    for(int i=0;remove[i];i++){
        flags[remove[i]]=true;
    }
    int src=0;
    int dst=0;
    while(str[src]){
        if(!flags[ str[src] ]){
            str[dst++]=str[src];
        }
        src++;
    }
    str[dst]=0;
    return str;
}


char* reversewords(char* str){
    char* ret=new char[strlen(str)];
    int p=0;
    for(int i=strlen(str);i>=0;){
        int j,k;
        for(j=i-1;j>=0 && str[j] != ' ';j--);
        for(k=j+1;k<i;k++){
            ret[p++]=str[k];
        }
        ret[p++]=' ';
        i=j;
    }
    ret[p]=0;
    strcpy(str,ret);
    delete []ret;
    return str;
}


void reversestring(char* str, int start, int end){
    for(;end>start;start++,end--){
        char ch=str[start];
        str[start]=str[end];
        str[end]=ch;
    }
}

char* reversewordsinplace(char* str){
    int len=strlen(str);
    reversestring(str,0,len-1);

    int i,j;
    for(i=0;i<len;){
        for(j=i;str[j]&&str[j]!=' ';j++);
        reversestring(str,i,j-1);
        i=j+1;
    }

    return str;
}


int str2int(char* str){
    int sign=1;
    int i=0;
    if(str[0]=='-'){
        sign=-1;
        i=1;
    }
    int val=0;
    for(;str[i];i++){
        val*=10;
        val+=str[i]-'0';
    }
    val*=sign;
    return val;
}


char* int2str(int n){
    static char str[128];
    int p=0;
    bool bnegative=false;
    if(n<0){
        bnegative=true;
        n*=-1;
    }

    do{
        str[p++]=n%10+'0';
        n/=10;
    }while(n);

    if(bnegative){
        str[p++]='-';
    }
    str[p]=0;
    reversestring(str,0,strlen(str)-1);
    return str;
}




int main()
{
    char str[]="the war of vowels";
    std::cout<<str<<std::endl;
    std::cout<<removechars(str,"aeiou")<<std::endl;

    char str2[]="do or do not, there is no try.";
    std::cout<<str2<<std::endl;
    std::cout<<reversewords(str2)<<std::endl;

    char str3[]="do or do not, there is no try.";
    std::cout<<str3<<std::endl;
    std::cout<<reversewordsinplace(str3)<<std::endl;

    std::cout<<str2int("1234")<<std::endl;
    std::cout<<str2int("-1234")<<std::endl;
    std::cout<<str2int("1")<<std::endl;
    std::cout<<str2int("0")<<std::endl;
    std::cout<<str2int("-1")<<std::endl;

    std::cout<<int2str(1234)<<std::endl;
    std::cout<<int2str(-1234)<<std::endl;
    std::cout<<int2str(1)<<std::endl;
    std::cout<<int2str(0)<<std::endl;
    std::cout<<int2str(-1)<<std::endl;

	return 0;
}
